export default {
  baidu: str => {
    return new Promise((resolve, reject) => {
      fetch("https://fanyi.baidu.com/transapi", {
        headers: {
          "content-type": "application/json"
        },
        body: JSON.stringify({
          from: "en",
          to: "zh",
          query: str,
          source: "txt"
        }),
        method: "POST"
      })
        .then(res => res.json())
        .then(data => {
          resolve(data.result ? JSON.parse(data.result) : data);
        });
    });
  }
}
